package com.caration.shell;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

import android.app.ActivityGroup;
import android.app.AlertDialog;
import android.app.Dialog;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Process;
import android.text.Selection;
import android.text.SpannableStringBuilder;
import android.text.method.TextKeyListener;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.Toast;

import com.caration.sdk.utilities.Logger;
import com.caration.shell.config.CommonConfig;
import com.caration.shell.config.ConfigManger;
import com.caration.shell.cr3d.GLHandler;
import com.caration.shell.cr3d.RenderRunnable;
import com.caration.shell.cr3d.SharedData;
import com.caration.shell.item.AppWidgetInfo;
import com.caration.shell.preference.SettingPreferenceActivity;
import com.caration.shell.theme.inside.ThemeManager;
import com.caration.shell.utils.b;
import com.caration.shell.workspace2D.DragController;
import com.caration.shell.workspace2D.RootController;
import com.caration.shell.workspace2D.DragLayer;
import com.caration.shell.workspace2D.ScreenLayout;
import com.caration.shell.workspace2D.ShellAppWidgetHost;
import com.caration.shell.workspace2D.ShellGLSurfaceView;
import com.caration.shell.workspace2D.ShellMenuInfo;
import com.caration.shell.workspace2D.Workspace;
import com.caration.shell.workspace3D.ShellRenderHost;

public final class Home extends ActivityGroup implements OnLongClickListener {
	public static final int APPWIDGET_HOST_ID = 1024;
	public static int a = (int) (1000.0D + 2.0D * (1000.0D * Math.random()));
	private static Home sInstance;
	private LocaleConfiguration mLocaleConfig = null;
	private LoadingDialog mLoadingDialog;
	private ShellAppWidgetHost mWidgetHost;
	private Locale mLocale;
	private HashMap D = new HashMap();
	private int E = 5000;
	private com.tsf.shell.workspace3D.af F;
	RenderRunnable mRenderRun;
	private final BroadcastReceiver mCloseDialogReceiver = new BroadcastReceiver() {
		@Override
		public void onReceive(Context context, Intent intent) {
			closeAllPanels();
		}
	};
	private final ContentObserver mWidgetObserver = new ContentObserver(
			new Handler()) {
		public void onChange(boolean selfChange) {
			// TODO:
		};
	};
	private DragController mController;
	private DragLayer mDragLayer;
	private ShellGLSurfaceView mGLView;
	private Workspace mWorkspace;
	private AppWidgetManager mWidgetManager;
	private ShellMenuInfo mMenuInfo;
	private ShellMenuInfo l;
	private final int[] m = new int[2];
	private SpannableStringBuilder mSpannableBuilder = null;
	private boolean o = true;
	private boolean isPaused = true;
	private boolean q;
	private boolean r = false;
	private boolean s = false;
	private ShellModel mShellMode;
	private ArrayList v = new ArrayList();
	private ShellRenderHost mRenderHost;
	private ThemeManager mThemeManager;
	private b y;
	private ShellHandler mShellHandler;

	public static Home getInstance() {
		return sInstance;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		SharedData.setupDensity(this);
		CommonConfig.initialize();
		switch (CommonConfig.getScreenOrientation()) {
		case 0:
			if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_LANDSCAPE)
				setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT);
			else
				setRequestedOrientation(Configuration.ORIENTATION_UNDEFINED);
			break;
		case 1:
			setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT);
			break;
		case 2:
			setRequestedOrientation(Configuration.ORIENTATION_UNDEFINED);
			break;
		default:
			setRequestedOrientation(Configuration.ORIENTATION_PORTRAIT);
			break;
		}
		CommonConfig.setLiveWallpaperFlag(ShellWallpaperManager
				.isLiveWallpaper(this));
		mDragLayer = new DragLayer(this);
		if (sInstance == null) {
			sInstance = this;
			setContentView(mDragLayer);
			if (CommonConfig.isStartupError()) {
				int times = CommonConfig.getStartupErrorTimes();
				if (times <= 0) {
					CommonConfig.setStartupErrorTimes(times + 1);
					init();
				} else {
					AlertHelper.showDialog(
							R.string.notic_restore_startup_notic,
							new Runnable() {

								@Override
								public void run() {
									CommonConfig.clearErrorRecord();
									ConfigManger.clearAll();
									init();
								}
							}, new Runnable() {

								@Override
								public void run() {
									init();
								}
							});
				}
			} else {
				CommonConfig.setStartupError(true);
				init();
			}
		} else {
			setContentView(mDragLayer);
			restart();
		}
	}

	// d
	private void init() {
		r = true;
		s = false;
		SharedData.setupDensity(this);
		mThemeManager = new ThemeManager(this, ShellApplication.getModel());
		mLoadingDialog = new LoadingDialog(this);
		mLocale = getResources().getConfiguration().locale;
		mGLView = new ShellGLSurfaceView(this);
		mDragLayer.addView(mGLView);
		mShellHandler = new ShellHandler();
		// y = new com.tsf.shell.b();
		mWidgetHost = new ShellAppWidgetHost(this);
		mLoadingDialog.show();
		mRenderHost = new ShellRenderHost(mGLView);
		mRenderHost.putEvent(ShellRenderHost.EVENT_READY, this,
				"onWorkspace3dReady", new Object[0]);
		mRenderHost.putEvent(ShellRenderHost.EVENT_INIT_COMPLETE, this,
				"onWorkspace3dInitComplete", new Object[0]);
		mController = new DragController(this);
		mController.b(mDragLayer);
		mDragLayer.setController(mController);
		mWorkspace = new Workspace(this);
		mWorkspace.setController(mController);
		// mWorkspace.a(ShellRenderHost.h());
		mWorkspace.setOnLongClickListener(this);
		mController.a(mWorkspace);
		mController.a(mWorkspace);
		mDragLayer.addView(mWorkspace);
		getApplication();
		mShellMode = ShellApplication.a(this);
		mWidgetManager = AppWidgetManager.getInstance(this);
		mWidgetHost.startListening();
		checkLocaleConfig();
		getContentResolver().registerContentObserver(
				ShellProvider.CONTENT_APPWIDGET_RESET_URI, true,
				mWidgetObserver);
		mSpannableBuilder = new SpannableStringBuilder();
		Selection.setSelection(mSpannableBuilder, 0);
		IntentFilter intentfilter = new IntentFilter(
				Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
		registerReceiver(mCloseDialogReceiver, intentfilter);
	}

	/**
	 * Restart Application
	 */
	public void restart() {
		CommonConfig.setStartupError(false);
		Intent restart = new Intent(this, Restart.class);
		restart.putExtra("pid", Process.myPid());
		startActivity(restart);
		finish();
	}

	public void restartDelayed() {
		SharedData.getGLHandler().postDelayed(new Runnable() {
			@Override
			public void run() {
				restart();
			}
		}, 100l);
	}

	private void a(ShellMenuInfo menuInfo) {
		mMenuInfo = menuInfo;
		this.q = true;
		SharedData.getGLHandler().post(new Runnable() {
			@Override
			public void run() {
				// if (F == null)
				// F = new com.tsf.shell.u(this);
				// F.b();
			}
		});
	}

	private static boolean a(ShellMenuInfo menuInfo, int paramInt1,
			int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean) {
		boolean success = true;
		boolean bool = menuInfo.mScreen.a(paramInt1, paramInt2, paramInt3,
				paramInt4);
		int[] arrayOfInt;
		if ((paramBoolean) && (!bool)) {
			arrayOfInt = menuInfo.mScreen.a((float) paramInt1,
					(float) paramInt2, paramInt3, paramInt4);
			if (arrayOfInt != null) {
				menuInfo.b = arrayOfInt[0];
				menuInfo.c = arrayOfInt[1];
			}
		} else {
			success = bool;
		}

		return success;
	}

	public static void startSettings() {
		SettingPreferenceActivity.startup();
	}

	private boolean p() {
		return o || q;
	}

	private void q() {
		if (this.F != null)
			this.F.c();
	}

	private boolean r() {
		return isPaused;
		// int i1;
		// if (!isPaused) {
		// i1 = 0;
		// } else {
		// Log.i("Home", "setLoadOnResume");
		// i1 = 1;
		// }
		// return i1;
	}

	final void closeAllPanels() {
		getWindow().closeAllPanels();
		this.q = false;
	}

	// a
	public final void removeAppWidget(final AppWidgetInfo widget) {
		ShellRenderHost.o().d(widget);
		if ((widget.mContainer == -1) && ((widget instanceof AppWidgetInfo)))
			this.v.remove(widget);
		if ((widget instanceof AppWidgetInfo)) {
			if (mWidgetHost != null)
				new Thread("deleteAppWidgetId") {
					public void run() {
						mWidgetHost.deleteAppWidgetId(widget.mWidgetId);
					};
				}.start();
		}
		new StringBuilder("removeAppWidget:").append(widget.mWidgetId)
				.toString();
		DbHelper.deleteItemInfo(this, widget);
	}

	private void checkLocaleConfig() {
		if (mLocaleConfig != null) {
			Configuration config = getResources().getConfiguration();
			String lastLocale = mLocaleConfig.locale;
			String locale = config.locale.toString();
			int lastMcc = mLocaleConfig.mcc;
			int mcc = config.mcc;
			int lastMnc = mLocaleConfig.mnc;
			int mnc = config.mnc;
			if ((!locale.equals(lastLocale)) || (mcc != lastMcc)
					|| (mnc != lastMnc)) {
				mLocaleConfig.locale = locale;
				mLocaleConfig.mcc = mcc;
				mLocaleConfig.mnc = mnc;
				new Thread("WriteLocaleConfiguration") {
					public void run() {
						writeLocaleConfig(mLocaleConfig);
					};
				}.start();
			}
		} else {
			new WriteLocaleTask().execute(null);
		}
	}

	class WriteLocaleTask extends AsyncTask<String, Integer, Object> {

		@Override
		protected Object doInBackground(String... params) {
			LocaleConfiguration locale = new LocaleConfiguration();
			readLocaleConfig(locale);
			return locale;
		}

		@Override
		protected void onPostExecute(Object result) {
			mLocaleConfig = (LocaleConfiguration) result;
			checkLocaleConfig();
		}
	}

	private void readLocaleConfig(LocaleConfiguration locale) {
		DataInputStream datainputstream = null;
		datainputstream = new DataInputStream(
				openFileInput("launcher.preferences"));
		locale.locale = datainputstream.readUTF();
		locale.mcc = datainputstream.readInt();
		locale.mnc = datainputstream.readInt();
		datainputstream.close();
		// _L1:
		// return;
		// JVM INSTR pop ;
		// datainputstream = null;
		// _L4:
		// if(datainputstream != null)
		// try
		// {
		// datainputstream.close();
		// }
		// catch(IOException _ex) { }
		// goto _L1
		// JVM INSTR pop ;
		// datainputstream = null;
		// _L3:
		// if(datainputstream != null)
		// try
		// {
		// datainputstream.close();
		// }
		// catch(IOException _ex) { }
		// goto _L1
		// Exception exception;
		// exception;
		// _L2:
		// if(datainputstream != null)
		// try
		// {
		// datainputstream.close();
		// }
		// catch(IOException _ex) { }
		// throw exception;
		// JVM INSTR pop ;
		// goto _L1
		// exception;
		// datainputstream = datainputstream;
		// exception = exception;
		// goto _L2
		// JVM INSTR pop ;
		// goto _L3
		// JVM INSTR pop ;
		// goto _L4
	}

	private void writeLocaleConfig(LocaleConfiguration configuration) {
		DataOutputStream dataoutputstream = new DataOutputStream(
				openFileOutput("launcher.preferences", 0));
		dataoutputstream.writeUTF(configuration.locale);
		dataoutputstream.writeInt(configuration.mcc);
		dataoutputstream.writeInt(configuration.mnc);
		dataoutputstream.flush();
		dataoutputstream.close();
		// _L1:
		// return;
		// JVM INSTR pop ;
		// dataoutputstream = null;
		// _L4:
		// if(dataoutputstream != null)
		// try
		// {
		// dataoutputstream.close();
		// }
		// catch(IOException _ex) { }
		// goto _L1
		// JVM INSTR pop ;
		// dataoutputstream = null;
		// _L3:
		// context.getFileStreamPath("launcher.preferences").delete();
		// if(dataoutputstream != null)
		// try
		// {
		// dataoutputstream.close();
		// }
		// catch(IOException _ex) { }
		// goto _L1
		// Exception exception;
		// exception;
		// _L2:
		// if(dataoutputstream != null)
		// try
		// {
		// dataoutputstream.close();
		// }
		// catch(IOException _ex) { }
		// throw exception;
		// JVM INSTR pop ;
		// goto _L1
		// exception;
		// dataoutputstream = dataoutputstream;
		// exception = exception;
		// goto _L2
		// JVM INSTR pop ;
		// goto _L3
		// JVM INSTR pop ;
		// goto _L4
	}

	private void t() {
		if (this.mRenderRun != null) {
			SharedData.getGLHandler().queueEvent(mRenderRun);
			this.mRenderRun = null;
		}
	}

	public final int a(Intent paramIntent, a parama) {
		int i1 = this.E;
		if (!this.q) {
			this.q = true;
			this.D.put(Integer.valueOf(this.E), parama);
		}
		a(paramIntent, this.E);
		overridePendingTransition(2130968576, 2130968577);
		this.E = (1 + this.E);
		return i1;
	}

	public final void a(float paramFloat1, float paramFloat2) {
		this.m[0] = (int) paramFloat1;
		this.m[1] = (int) paramFloat2;
	}

	public final void a(Intent paramIntent) {
		
		ShellHandler.getInstance().a(new Runnable() {
			
			@Override
			public void run() {
				    SharedData.getGLHandler().queueEvent(new Runnable() {
						
						@Override
						public void run() {
//							int i = ShellRenderHost.h().x();
//						    if (i == -1)
//						      i = ShellRenderHost.h().i();
//						    float[] arrayOfFloat = a.b(Home.b(this.a.a)[0], Home.b(this.a.a)[1]);
//						    Intent localIntent = (Intent)this.b.getParcelableExtra("android.intent.extra.shortcut.INTENT");
//						    String str = this.b.getStringExtra("android.intent.extra.shortcut.NAME");
//						    Object localObject = (Bitmap)this.b.getParcelableExtra("android.intent.extra.shortcut.ICON");
//						    if (localObject == null)
//						    {
//						      localObject = this.b.getParcelableExtra("android.intent.extra.shortcut.ICON_RESOURCE");
//						      if ((localObject != null) && ((localObject instanceof Intent.ShortcutIconResource)))
//						        cn.a(str, (Intent.ShortcutIconResource)localObject, localIntent, i, arrayOfFloat[0], arrayOfFloat[1]);
//						    }
//						    else
//						    {
//						      cn.a(str, (Bitmap)localObject, localIntent, i, arrayOfFloat[0], arrayOfFloat[1]);
//						    }
						}
					});
			}
		});
	}

	public final void a(com.tsf.shell.b.h paramh) {
		this.y.a(paramh);
	}

	public final void a(String paramString) {
		ShellRenderHost.k().g().a(paramString);
	}

	public final void a(ArrayList paramArrayList) {
		this.y.a(paramArrayList);
	}

	public final void a(ArrayList paramArrayList, boolean paramBoolean) {
		r();
		q();
		this.y.a(paramArrayList, paramBoolean);
	}

	public final void a(String[] paramArrayOfString, int paramInt) {
		b.a(paramArrayOfString, paramInt);
	}

	public final void b(Intent paramIntent) {
		paramIntent.addFlags(268435456);
		try {
			startActivity(paramIntent);
			return;
		} catch (Exception localException) {
			while (true) {
				SharedData.getGLHandler().post(new ae(this));
				localException.printStackTrace();
			}
		}
	}

	public final void b(AppWidgetInfo paramb) {
		Object localObject = ShellRenderHost.h().d(paramb.d);
		if ((localObject != null)
				&& (((com.tsf.shell.workspace3D.f.a) localObject).l() != null)) {
			if (a(((com.tsf.shell.workspace3D.f.a) localObject).l().c(),
					paramb.e, paramb.f, paramb.h, paramb.i, false)) {
				localObject = mWorkspace;
				int i1 = paramb.m;
				AppWidgetProviderInfo localAppWidgetProviderInfo = mWidgetManager
						.getAppWidgetInfo(i1);
				paramb.n = ((com.tsf.shell.workspace2D.m) mWidgetHost
						.createView(this, i1, localAppWidgetProviderInfo));
				paramb.n.setAppWidget(i1, localAppWidgetProviderInfo);
				paramb.n.setTag(paramb);
				((Workspace) localObject).a(paramb.n, ShellRenderHost.h().d(paramb.d).l(),
						paramb.e, paramb.f, paramb.h, paramb.i, false);
				((Workspace) localObject).requestLayout();
				this.v.add(paramb);
				ShellRenderHost.o().c(paramb);
			} else {
				mWidgetHost.deleteAppWidgetId(paramb.m);
				bb.b(this, paramb);
			}
		} else {
			mWidgetHost.deleteAppWidgetId(paramb.m);
			bb.b(this, paramb);
		}
	}

	public final void b(ArrayList paramArrayList) {
		r();
		q();
		this.y.b(paramArrayList);
	}

	public final void b(ArrayList paramArrayList, boolean paramBoolean) {
		q();
		if (paramBoolean)
			mWorkspace.a(paramArrayList);
		this.y.b(paramArrayList, paramBoolean);
	}

	public final boolean dispatchKeyEvent(KeyEvent paramKeyEvent)
	  {
	    int i1 = 1;
	    if (paramKeyEvent.getAction() != 0)
	      if (paramKeyEvent.getAction() != i1)
	        break label64;
	    label64: boolean bool;
	    switch (paramKeyEvent.getKeyCode())
	    {
	    default:
	      switch (paramKeyEvent.getKeyCode())
	      {
	      default:
	        bool = super.dispatchKeyEvent(paramKeyEvent);
	      case 3:
	      }
	    case 3:
	    }
	    return bool;
	  }

	// e
	public final Workspace getWorkspace() {
		return mWorkspace;
	}

	public final void f() {
		int i1 = mWidgetHost.allocateAppWidgetId();
		Intent localIntent;
		if (Build.VERSION.SDK_INT >= 16) {
			localIntent = new Intent();
			localIntent
					.setClass(SharedData.getContext(), AppWidgetPicker.class);
		} else {
			localIntent = new Intent("android.appwidget.action.APPWIDGET_PICK");
		}
		localIntent.putExtra("appWidgetId", i1);
		startActivityForResult(localIntent, 9);
	}

	public final void g() {
		if (com.tsf.shell.workspace3D.x.a()) {
			Bundle localBundle = new Bundle();
			Intent localIntent = new Intent();
			localIntent
					.setClass(SharedData.getContext(), ShortcutsPicker.class);
			localIntent.putExtra("android.intent.extra.INTENT", new Intent(
					"android.intent.action.CREATE_SHORTCUT"));
			localIntent.putExtra("android.intent.extra.TITLE",
					getText(2131361810));
			localIntent.putExtras(localBundle);
			startActivityForResult(localIntent, 7);
		}
	}

	public final void h() {
		startActivityForResult(Intent.createChooser(new Intent(
				"android.intent.action.SET_WALLPAPER"), getText(2131361801)),
				10);
	}

	public final void j() {
		Intent localIntent = new Intent();
		localIntent.setAction("android.settings.SETTINGS");
		b(localIntent);
	}

	public final void k() {
		if (Workspace.c() != null)
			a(Workspace.c());
	}

	final void l() {
		getWindow().closeAllPanels();
		this.q = false;
	}

	public final void m() {
		Workspace locals = mWorkspace;
		int i1 = locals.getChildCount();
		for (int i2 = 0; i2 < i1; i2++)
			((ViewGroup) locals.getChildAt(i2)).removeAllViewsInLayout();
	}

	public final void n() {
		r();
		this.o = false;
	}

	public final boolean o() {
		int i1;
		if (!isPaused)
			i1 = 1;
		else
			i1 = 0;
		return i1;
	}

	protected final void onActivityResult(int paramInt1, int paramInt2,
			Intent paramIntent) {
		while (true) {
			this.q = false;
			if (this.D.containsKey(Integer.valueOf(paramInt1))) {
				((a) this.D.get(Integer.valueOf(paramInt1))).a(paramInt1,
						paramInt2, paramIntent);
				this.D.remove(Integer.valueOf(paramInt1));
			}
			if ((paramInt2 != -1) || (mMenuInfo == null)) {
				if (((paramInt1 != 9) && (paramInt1 != 5)) || (paramInt2 != 0)
						|| (paramIntent == null))
					break;
				int i1 = paramIntent.getIntExtra("appWidgetId", -1);
				if (i1 == -1)
					break;
				mWidgetHost.deleteAppWidgetId(i1);
			} else {
				Object localObject1;
				int i2;
				AppWidgetProviderInfo localAppWidgetProviderInfo;
				switch (paramInt1) {
				case 1:
					a(paramIntent);
					break;
				case 5:
					localObject1 = mMenuInfo;
					i2 = paramIntent.getExtras().getInt("appWidgetId", -1);
					localAppWidgetProviderInfo = mWidgetManager
							.getAppWidgetInfo(i2);
					if (localAppWidgetProviderInfo == null)
						break;
					int[] arrayOfInt = ScreenLayout.a(
							localAppWidgetProviderInfo.minWidth,
							localAppWidgetProviderInfo.minHeight);
					if (a((ShellMenuInfo) localObject1,
							((ShellMenuInfo) localObject1).b,
							((ShellMenuInfo) localObject1).c, arrayOfInt[0],
							arrayOfInt[1], true)) {
						AppWidgetInfo localb = new AppWidgetInfo(i2);
						localb.h = arrayOfInt[0];
						localb.i = arrayOfInt[1];
						int i5 = ShellRenderHost.h().x();
						int i4 = ((ShellMenuInfo) localObject1).b;
						int i3 = ((ShellMenuInfo) localObject1).c;
						localb.c = -1;
						localb.d = i5;
						localb.e = i4;
						localb.f = i3;
						ContentValues localContentValues = new ContentValues();
						Object localObject2 = getContentResolver();
						localb.a(localContentValues);
						localb.b();
						localObject2 = ((ContentResolver) localObject2).insert(
								ch.b, localContentValues);
						if (localObject2 != null)
							localb.a = Integer
									.parseInt((String) ((Uri) localObject2)
											.getPathSegments().get(1));
						this.v.add(localb);
						localb.n = ((com.tsf.shell.workspace2D.m) mWidgetHost
								.createView(this, i2,
										localAppWidgetProviderInfo));
						localb.n.setAppWidget(i2, localAppWidgetProviderInfo);
						localb.n.setTag(localb);
						mWorkspace.a(localb.n,
								((ShellMenuInfo) localObject1).b,
								((ShellMenuInfo) localObject1).c, localb.h,
								localb.i, p());
						ShellRenderHost.o().c(localb);
					} else {
						if (i2 != -1)
							mWidgetHost.deleteAppWidgetId(i2);
						ap.a(2131361819);
					}
					break;
				case 7:
					startActivityForResult(paramIntent, 1);
					break;
				case 9:
					i2 = paramIntent.getIntExtra("appWidgetId", -1);
					localAppWidgetProviderInfo = mWidgetManager
							.getAppWidgetInfo(i2);
					if ((localAppWidgetProviderInfo == null)
							|| (localAppWidgetProviderInfo.configure == null)) {
						paramInt2 = -1;
						paramInt1 = 5;
						continue;
					}
					localObject1 = new Intent(
							"android.appwidget.action.APPWIDGET_CONFIGURE");
					((Intent) localObject1)
							.setComponent(localAppWidgetProviderInfo.configure);
					((Intent) localObject1).putExtra("appWidgetId", i2);
					a((Intent) localObject1, 5);
				case 2:
				case 3:
				case 4:
				case 6:
				case 8:
				}
			}
		}
	}

	public final void onConfigurationChanged(Configuration paramConfiguration) {
		super.onConfigurationChanged(paramConfiguration);
		if ((mLocale != null) && (!mLocale.equals(paramConfiguration.locale)))
			a();
	}

	protected final Dialog onCreateDialog(int paramInt) {
		Object localObject;
		switch (paramInt) {
		default:
			localObject = super.onCreateDialog(paramInt);
			break;
		case 10:
			localObject = new AlertDialog.Builder(this);
			((AlertDialog.Builder) localObject).setCancelable(false);
			((AlertDialog.Builder) localObject).setMessage(2131361865)
					.setPositiveButton(2131361866, new o(this))
					.setNegativeButton(2131361867, new p(this));
			localObject = ((AlertDialog.Builder) localObject).create();
			break;
		case 11:
			localObject = new AlertDialog.Builder(this).setMessage(2131361868)
					.setPositiveButton(2131361869, new q(this))
					.setNegativeButton(2131361870, new s(this)).create();
		}
		return (Dialog) localObject;
	}

	public final boolean onCreateOptionsMenu(Menu paramMenu) {
		int i1 = 0;
		int i2;
		if (!p()) {
			super.onCreateOptionsMenu(paramMenu);
			paramMenu.add(1, 2, 0, 2131361820).setIcon(17301555)
					.setAlphabeticShortcut('A');
			paramMenu.add(0, 3, 0, 2131361821).setIcon(17301570)
					.setAlphabeticShortcut('M');
			paramMenu.add(2, 4, 0, 2131361822).setIcon(17301567)
					.setAlphabeticShortcut('W');
			paramMenu.add(0, 5, 0, 2131361823).setIcon(17301567);
			paramMenu.add(0, 6, 0, "TSF").setIcon(17301573)
					.setAlphabeticShortcut('N');
			Intent localIntent = new Intent("android.settings.SETTINGS");
			localIntent.setFlags(270532608);
			paramMenu.add(0, 7, 0, 2131361826).setIcon(17301577)
					.setAlphabeticShortcut('P').setIntent(localIntent);
			i2 = 1;
		}
		return i2;
	}

	public final void onDestroy() {
		super.onDestroy();
		try {
			mWidgetHost.stopListening();
			try {
				label11: TextKeyListener.getInstance().release();
				mShellMode.b();
				Iterator localIterator = this.v.iterator();
				while (true) {
					if (!localIterator.hasNext()) {
						getContentResolver().unregisterContentObserver(this.e);
						unregisterReceiver(mCloseDialogReceiver);
						break;
					}
					((com.tsf.shell.b.a) localIterator.next()).c();
				}
			} catch (Exception localException) {
			}
		} catch (NullPointerException localNullPointerException) {
			break label11;
		}
	}

	public final void onInitialzeDataComplete() {
		com.censivn.C3DEngine.a.f().g();
		aa localaa = new aa(this);
		com.censivn.C3DEngine.a.a().a(localaa);
	}

	public final boolean onKeyDown(int paramInt, KeyEvent paramKeyEvent) {
		boolean bool1 = true;
		n localn = new n(this, paramInt, paramKeyEvent);
		com.censivn.C3DEngine.a.a();
		com.censivn.C3DEngine.b.w.c(localn);
		if (paramInt != 4) {
			if ((paramInt != 82) || (!paramKeyEvent.isLongPress())) {
				if (paramInt == 24)
					com.censivn.C3DEngine.a.f().e();
				boolean bool2 = super.onKeyDown(paramInt, paramKeyEvent);
				if (!bool2) {
					if (((InputMethodManager) getSystemService("input_method"))
							.isFullscreenMode())
						bool1 = false;
					if ((bool1)
							&& (paramInt != 66)
							&& (TextKeyListener.getInstance().onKeyDown(
									mWorkspace, mSpannableBuilder, paramInt,
									paramKeyEvent))
							&& (mSpannableBuilder != null)
							&& (mSpannableBuilder.length() > 0))
						;
				} else {
					bool1 = bool2;
					break label151;
				}
				bool1 = onSearchRequested();
			} else {
				bool1 = bool1;
			}
		} else
			bool1 = bool1;
		label151: return bool1;
	}

	public final boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent) {
		ag localag = new ag(this, paramInt, paramKeyEvent);
		com.censivn.C3DEngine.a.a();
		com.censivn.C3DEngine.b.w.c(localag);
		return super.onKeyUp(paramInt, paramKeyEvent);
	}

	public final boolean onLongClick(View paramView) {
		int i1;
		if (!p()) {
			if ((paramView instanceof ScreenLayout))
				localObject = paramView;
			else
				localObject = (View) paramView.getParent();
			Object localObject = (ShellMenuInfo) ((View) localObject).getTag();
			if (localObject != null) {
				if (mWorkspace.a())
					if (((ShellMenuInfo) localObject).a != null) {
						if (com.tsf.shell.workspace3D.x.a()) {
							mWorkspace.performHapticFeedback(0, 1);
							mWorkspace.a((ShellMenuInfo) localObject);
						} else {
							i1 = 1;
							break label122;
						}
					} else {
						mWorkspace.b();
						mWorkspace.performHapticFeedback(0, 1);
						a(i1);
					}
				i1 = 1;
			} else {
				i1 = 1;
			}
		} else {
			i1 = 0;
		}
		label122: return i1;
	}

	protected final void onNewIntent(Intent paramIntent) {
		super.onNewIntent(paramIntent);
		if ("android.intent.action.MAIN".equals(paramIntent.getAction())) {
			l();
			int i1;
			if ((0x400000 & paramIntent.getFlags()) == 4194304)
				i1 = 0;
			else
				i1 = 1;
			if ((i1 != 0) && (this.s) && (ShellRenderHost.h() != null))
				ak.a(3);
			View localView = getWindow().peekDecorView();
			if ((localView != null) && (localView.getWindowToken() != null))
				((InputMethodManager) getSystemService("input_method"))
						.hideSoftInputFromWindow(localView.getWindowToken(), 0);
		}
	}

	public final boolean onOptionsItemSelected(MenuItem paramMenuItem) {
		boolean bool = true;
		switch (paramMenuItem.getItemId()) {
		default:
			bool = super.onOptionsItemSelected(paramMenuItem);
			break;
		case 2:
			if (ShellRenderHost.h().x() == -1)
				ap.a(2131361840);
			else
				a(this.l);
			break;
		case 3:
			startActivity(new Intent(
					"android.settings.MANAGE_APPLICATIONS_SETTINGS"));
			break;
		case 4:
			h();
			break;
		case 5:
			ThemeManagerActivity.a();
			break;
		case 6:
			SettingPreferenceActivity.a();
		}
		return bool;
	}

	protected final void onPause() {
		super.onPause();
		isPaused = true;
		t();
		if (this.r) {
			mShellHandler.a("Home");
			mRenderHost.g();
		}
		com.tsf.shell.workspace3D.x.b();
	}

	protected final void onPrepareDialog(int paramInt, Dialog paramDialog) {
	}

	public final boolean onPrepareOptionsMenu(Menu paramMenu) {
		super.onPrepareOptionsMenu(paramMenu);
		paramMenu.setGroupVisible(1, true);
		paramMenu.setGroupVisible(2, true);
		this.l = Workspace.c();
		boolean bool;
		if ((this.l == null) || (!ShellRenderHost.m().n()) || (ShellRenderHost.h().g() != 2))
			bool = false;
		else
			bool = true;
		paramMenu.setGroupEnabled(1, bool);
		return true;
	}

	protected final void onResume() {
		super.onResume();
		isPaused = false;
		if (this.r) {
			t();
			mRenderRun = new RenderRunnable(1, 1) {
				public void run() {
					mShellHandler.b("Home");
					mRenderHost.e();
					mRenderHost.getWallpaperManager().setWallpaperDimension();
					mRenderHost.getWallpaperManager().resetWallpaperMode();
				};
			};
			SharedData.getGLHandler().post(mRenderRun);
			mRenderHost.f();
		}
	}

	public final boolean onSearchRequested() {
		startSearch(null, false, null, true);
		return true;
	}

	public final void onWindowFocusChanged(boolean paramBoolean) {
		super.onWindowFocusChanged(paramBoolean);
		com.tsf.shell.action.q.b(paramBoolean);
	}

	public final void onWorkspace3dInitComplete() {
		ShellRenderHost.d();
		mLoadingDialog.b();
		cr.a();
		f localf = new f(getApplicationContext());
		localf.b();
		localf.a();
		ShellRenderHost.h().w();
		i.a();
		this.s = true;
		if (!com.tsf.shell.a.l.i())
			com.tsf.shell.action.q.a(4);
	}

	public final void onWorkspace3dReady() {
		com.censivn.C3DEngine.a.f().f();
		ShellModel.a();
		mShellMode.a(this, true);
	}

	@Override
	public void startActivity(Intent intent) {
		try {
			super.startActivity(intent);
			overridePendingTransition(R.anim.app_enter, R.anim.app_exit);
		} catch (Exception localException) {
			while (true) {
				SharedData.getGLHandler().post(new Runnable() {
					@Override
					public void run() {
						Toast.makeText(Home.this, R.string.activity_not_found,
								Toast.LENGTH_SHORT).show();
					}
				});
			}
		}

	}

	@Override
	public void startActivityForResult(Intent intent, int requestCode) {
		try {
			if (requestCode >= 0)
				this.q = true;
			super.startActivityForResult(intent, requestCode);
			overridePendingTransition(R.anim.app_enter, R.anim.app_exit);
		} catch (Exception localException) {
			while (true) {
				SharedData.getGLHandler().post(new Runnable() {
					@Override
					public void run() {
						Toast.makeText(Home.this, R.string.activity_not_found,
								Toast.LENGTH_SHORT).show();
					}
				});
			}
		}
		
	}
}
